package com.hlhj.funlike_business.api

import android.app.Application
import com.example.mymvp.okrx.JsonConvert
import com.hlhj.funlike_business.bean.*
import com.hlhj.funlike_business.constant.Constants
import com.hlhj.funlike_business.data.SPUser
import com.lzy.okgo.OkGo
import com.lzy.okgo.model.Response
import com.lzy.okrx2.adapter.ObservableResponse
import io.reactivex.Observable
import io.reactivex.schedulers.Schedulers
import java.io.File
import javax.xml.transform.OutputKeys

object Apis {
    //商家登录
    fun Login(login:String,password:String):Observable<Response<LoginBean>>{
        return OkGo.post<LoginBean>(Constants.SHOP_USER_LOGIN)
                .params("login",login)
                .params("password",password)
                .converter(object : JsonConvert<LoginBean>() {})
                .adapt(ObservableResponse<LoginBean>())
                .subscribeOn(Schedulers.io())
    }
    //商铺配置信息
    fun ShopConfig():Observable<Response<ShopInfoBean>>{
        return OkGo.get<ShopInfoBean>(Constants.ShopConfig)
                .headers("token",SPUser.getUser(Application()).getToken())
                .converter(object :JsonConvert<ShopInfoBean>(){})
                .adapt(ObservableResponse<ShopInfoBean>())
                .subscribeOn(Schedulers.io())
    }
    //设置店铺名
    fun ShopName(shop_name:String):Observable<Response<MsgBean>>{
        return OkGo.post<MsgBean>(Constants.SHOP_NAME)
                .headers("token",SPUser.getUser(Application()).getToken())
                .params("shop_name",shop_name)
                .converter(object :JsonConvert<MsgBean>(){})
                .adapt(ObservableResponse<MsgBean>())
                .subscribeOn(Schedulers.io())
    }
    //设置广告语
    fun ShopAdvert(advertising:String):Observable<Response<MsgBean>>{
        return OkGo.post<MsgBean>(Constants.SHOP_ADVERT)
                .headers("token",SPUser.getUser(Application()).getToken())
                .params("advertising",advertising)
                .converter(object :JsonConvert<MsgBean>(){})
                .adapt(ObservableResponse<MsgBean>())
                .subscribeOn(Schedulers.io())
    }
    //店铺相册
    fun ShopPhoto():Observable<Response<ShopPhotoBean>>{
        return OkGo.get<ShopPhotoBean>(Constants.SHOP_IMG)
                .headers("token",SPUser.getUser(Application()).getToken())
                .converter(object :JsonConvert<ShopPhotoBean>(){})
                .adapt(ObservableResponse<ShopPhotoBean>())
                .subscribeOn(Schedulers.io())
    }
    //设置电话
    fun ShopPhoneTel(tel:String):Observable<Response<MsgBean>>{
        return OkGo.post<MsgBean>(Constants.SHOP_TEL)
                .headers("token",SPUser.getUser(Application()).getToken())
                .params("tel",tel)
                .converter(object :JsonConvert<MsgBean>(){})
                .adapt(ObservableResponse<MsgBean>())
                .subscribeOn(Schedulers.io())
    }
    //设置配送范围
    fun ShopCricle(distance:String):Observable<Response<MsgBean>>{
        return OkGo.post<MsgBean>(Constants.SHOP_CIRCLE)
                .headers("token",SPUser.getUser(Application()).getToken())
                .params("distance",distance)
                .converter(object :JsonConvert<MsgBean>(){})
                .adapt(ObservableResponse<MsgBean>())
                .subscribeOn(Schedulers.io())
    }
    //设置营业时间
    fun ShopBusiness(business_start:String,business_end:String):Observable<Response<MsgBean>>{
        return OkGo.post<MsgBean>(Constants.SHOP_BUSINESS)
                .headers("token",SPUser.getUser(Application()).getToken())
                .params("business_start",business_start)
                .params("business_end",business_end)
                .converter(object :JsonConvert<MsgBean>(){})
                .adapt(ObservableResponse<MsgBean>())
                .subscribeOn(Schedulers.io())
    }
    //获取配送方式
    fun ShopGetTakeType():Observable<Response<TakeTypeBean>>{
        return OkGo.get<TakeTypeBean>(Constants.SHOP_GETTAKETYPE)
                .headers("token",SPUser.getUser(Application()).getToken())
                .converter(object :JsonConvert<TakeTypeBean>(){})
                .adapt(ObservableResponse<TakeTypeBean>())
                .subscribeOn(Schedulers.io())
    }
    //设置配送方式
    fun ShopTakeType(distribution:Int,freight:String,freight_long:Int):Observable<Response<MsgBean>>{
        return OkGo.post<MsgBean>(Constants.SHOP_TAKETYPE)
                .headers("token",SPUser.getUser(Application()).getToken())
                .params("distribution",distribution)
                .params("freight",freight)
                .params("freight_long",freight_long)
                .converter(object :JsonConvert<MsgBean>(){})
                .adapt(ObservableResponse<MsgBean>())
                .subscribeOn(Schedulers.io())
    }
    //获取活动列表
    fun GetActivityList():Observable<Response<ActivityBean>>{
        return OkGo.get<ActivityBean>(Constants.GetActivityList)
                .headers("token",SPUser.getUser(Application()).getToken())
                .converter(object :JsonConvert<ActivityBean>(){})
                .adapt(ObservableResponse<ActivityBean>())
                .subscribeOn(Schedulers.io())
    }
    //添加活动
    fun AddActivity(condition:String,activity_value:String):Observable<Response<MsgBean>>{
        return OkGo.post<MsgBean>(Constants.AddActivity)
                .headers("token",SPUser.getUser(Application()).getToken())
                .params("condition",condition)
                .params("activity_value",activity_value)
                .converter(object :JsonConvert<MsgBean>(){})
                .adapt(ObservableResponse<MsgBean>())
                .subscribeOn(Schedulers.io())
    }
    //删除
    fun DelActivity(id:Int):Observable<Response<MsgBean>>{
        return OkGo.post<MsgBean>(Constants.DelActivity)
                .headers("token",SPUser.getUser(Application()).getToken())
                .params("id",id)
                .converter(object :JsonConvert<MsgBean>(){})
                .adapt(ObservableResponse<MsgBean>())
                .subscribeOn(Schedulers.io())
    }
    //商品分类列表
    fun GetGoodTypeList():Observable<Response<FoodTypeBean>>{
        return OkGo.get<FoodTypeBean>(Constants.GetGoodTypeList)
                .headers("token",SPUser.getUser(Application()).getToken())
                .converter(object :JsonConvert<FoodTypeBean>(){})
                .adapt(ObservableResponse<FoodTypeBean>())
                .subscribeOn(Schedulers.io())
    }
    //添加商品分类
    fun AddGoodType(type_name:String):Observable<Response<AddGoodBean>>{
        return OkGo.post<AddGoodBean>(Constants.AddGoodType)
                .headers("token",SPUser.getUser(Application()).getToken())
                .params("type_name",type_name)
                .converter(object :JsonConvert<AddGoodBean>(){})
                .adapt(ObservableResponse<AddGoodBean>())
                .subscribeOn(Schedulers.io())
    }
    //删除商品分类
    fun DelGoodType(id:Int):Observable<Response<MsgBean>>{
        return OkGo.post<MsgBean>(Constants.DelGoodType)
                .headers("token",SPUser.getUser(Application()).getToken())
                .params("id",id)
                .converter(object :JsonConvert<MsgBean>(){})
                .adapt(ObservableResponse<MsgBean>())
                .subscribeOn(Schedulers.io())
    }
    //商品列表
    fun FoodList(type_id:Int,p:Int,num:Int):Observable<Response<FoodListBean>>{
        return OkGo.get<FoodListBean>(Constants.FoodList)
                .headers("token",SPUser.getUser(Application()).getToken())
                .params("type_id",type_id)
                .params("p",p)
                .params("num",10)
                .converter(object :JsonConvert<FoodListBean>(){})
                .adapt(ObservableResponse<FoodListBean>())
                .subscribeOn(Schedulers.io())
    }
    //设置是否营业
    fun ShopStatus(shop_status:Int):Observable<Response<MsgBean>>{
        return OkGo.post<MsgBean>(Constants.EditShopStatus)
                .headers("token",SPUser.getUser(Application()).getToken())
                .params("shop_status",shop_status)
                .converter(object :JsonConvert<MsgBean>(){})
                .adapt(ObservableResponse<MsgBean>())
                .subscribeOn(Schedulers.io())
    }
    //商品上下架
    fun FoodStatus(id:Int,status:Int):Observable<Response<MsgBean>>{
        return OkGo.post<MsgBean>(Constants.FoodStatus)
                .headers("token",SPUser.getUser(Application()).getToken())
                .params("id",id)
                .params("status",status)
                .converter(object :JsonConvert<MsgBean>(){})
                .adapt(ObservableResponse<MsgBean>())
                .subscribeOn(Schedulers.io())
    }
    //商品详情
    fun FoodDetail(id:Int):Observable<Response<FoodDetailBean>>{
        return OkGo.post<FoodDetailBean>(Constants.FoodDetail)
                .headers("token",SPUser.getUser(Application()).getToken())
                .params("id",id)
                .converter(object :JsonConvert<FoodDetailBean>(){})
                .adapt(ObservableResponse<FoodDetailBean>())
                .subscribeOn(Schedulers.io())
    }
    //删除商品
    fun FoodDel(id:Int):Observable<Response<MsgBean>>{
        return OkGo.post<MsgBean>(Constants.FoodDel)
                .headers("token",SPUser.getUser(Application()).getToken())
                .params("id",id)
                .converter(object :JsonConvert<MsgBean>(){})
                .adapt(ObservableResponse<MsgBean>())
                .subscribeOn(Schedulers.io())
    }
    //删除图片
    fun DelPhoto(id:Int,slide_id:Int):Observable<Response<MsgBean>>{
        return OkGo.post<MsgBean>(Constants.DelPhoto)
                .headers("token",SPUser.getUser(Application()).getToken())
                .params("id",id)
                .params("slide_id",slide_id)
                .converter(object :JsonConvert<MsgBean>(){})
                .adapt(ObservableResponse<MsgBean>())
                .subscribeOn(Schedulers.io())
    }
    //订单列表
    fun OrderList(status:Int,p:Int,num:Int):Observable<Response<OrderListBean>>{
        return OkGo.get<OrderListBean>(Constants.OrderList)
                .headers("token",SPUser.getUser(Application()).getToken())
                .params("status",status)
                .params("p",p)
                .params("num",num)
                .converter(object :JsonConvert<OrderListBean>(){})
                .adapt(ObservableResponse<OrderListBean>())
                .subscribeOn(Schedulers.io())
    }
    //订单详情
    fun OrderDetail(order_id:Int):Observable<Response<OrderDetailBean>>{
        return OkGo.get<OrderDetailBean>(Constants.OrderDetail)
                .headers("token",SPUser.getUser(Application()).getToken())
                .params("order_id",order_id)
                .converter(object :JsonConvert<OrderDetailBean>(){})
                .adapt(ObservableResponse<OrderDetailBean>())
                .subscribeOn(Schedulers.io())
    }
    //修改订单状态
    fun EditOrderStatus(order_id:Int,status:Int):Observable<Response<MsgBean>>{
        return OkGo.post<MsgBean>(Constants.EditOrderStatus)
                .headers("token",SPUser.getUser(Application()).getToken())
                .params("order_id",order_id)
                .params("status",status)
                .converter(object :JsonConvert<MsgBean>(){})
                .adapt(ObservableResponse<MsgBean>())
                .subscribeOn(Schedulers.io())
    }
    //订单退单
    fun OrderChargeBack(order_id: Int):Observable<Response<MsgBean>>{
        return OkGo.post<MsgBean>(Constants.OrderChargeBack)
                .headers("token",SPUser.getUser(Application()).getToken())
                .params("order_id",order_id)
                .converter(object :JsonConvert<MsgBean>(){})
                .adapt(ObservableResponse<MsgBean>())
                .subscribeOn(Schedulers.io())
    }
    //店铺收益
    fun ShopMoney():Observable<Response<TotalBean>>{
        return OkGo.get<TotalBean>(Constants.TotalMoney)
                .headers("token",SPUser.getUser(Application()).getToken())
                .converter(object :JsonConvert<TotalBean>(){})
                .adapt(ObservableResponse<TotalBean>())
                .subscribeOn(Schedulers.io())
    }
    //流水记录
    fun WaterList(p:Int):Observable<Response<WaterListBean>>{
        return OkGo.get<WaterListBean>(Constants.WaterLsit)
                .headers("token",SPUser.getUser(Application()).getToken())
                .params("p",p)
                .converter(object :JsonConvert<WaterListBean>(){})
                .adapt(ObservableResponse<WaterListBean>())
                .subscribeOn(Schedulers.io())
    }
    //资质相册
    fun QualifacationAblums():Observable<Response<ShopPhotoBean>>{
        return OkGo.get<ShopPhotoBean>(Constants.QualifactionAblums)
                .headers("token",SPUser.getUser(Application()).getToken())
                .converter(object :JsonConvert<ShopPhotoBean>(){})
                .adapt(ObservableResponse<ShopPhotoBean>())
                .subscribeOn(Schedulers.io())
    }
    //评论列表
    fun CommentList(page:Int):Observable<Response<CommentListBean>>{
        return OkGo.get<CommentListBean>(Constants.CommentList)
                .headers("token",SPUser.getUser(Application()).getToken())
                .params("page",page)
                .converter(object :JsonConvert<CommentListBean>(){})
                .adapt(ObservableResponse<CommentListBean>())
                .subscribeOn(Schedulers.io())
    }
    //删除评论
    fun DelComment(id:Int):Observable<Response<MsgBean>>{
        return OkGo.post<MsgBean>(Constants.DelComment)
                .headers("token",SPUser.getUser(Application()).getToken())
                .params("id",id)
                .converter(object :JsonConvert<MsgBean>(){})
                .adapt(ObservableResponse<MsgBean>())
                .subscribeOn(Schedulers.io())
    }
    //回复评论
    fun ReplyComment(id:Int,reply_content:String):Observable<Response<MsgBean>>{
        return OkGo.post<MsgBean>(Constants.replyComment)
                .headers("token",SPUser.getUser(Application()).getToken())
                .params("id",id)
                .params("reply_content",reply_content)
                .converter(object :JsonConvert<MsgBean>(){})
                .adapt(ObservableResponse<MsgBean>())
                .subscribeOn(Schedulers.io())
    }
    //上传封面图片
    fun UpConverImg(shop:File):Observable<Response<UpImgBean>>{
        return OkGo.post<UpImgBean>(Constants.UpConverImg)
                .headers("token",SPUser.getUser(Application()).getToken())
                .params("shop",shop)
                .converter(object :JsonConvert<UpImgBean>(){})
                .adapt(ObservableResponse<UpImgBean>())
                .subscribeOn(Schedulers.io())
    }
    //上传资质图片
    fun UpQualificationsImg(shop:File):Observable<Response<UpImgBean1>>{
        return OkGo.post<UpImgBean1>(Constants.UpQualificationsImg)
                .headers("token",SPUser.getUser(Application()).getToken())
                .params("shop",shop)
                .converter(object :JsonConvert<UpImgBean1>(){})
                .adapt(ObservableResponse<UpImgBean1>())
                .subscribeOn(Schedulers.io())
    }
    //上传相册图片
    fun UpShopImg(image:File):Observable<Response<UpImgBean1>>{
        return OkGo.post<UpImgBean1>(Constants.UpShopImg)
                .headers("token",SPUser.getUser(Application()).getToken())
                .params("image",image)
                .converter(object :JsonConvert<UpImgBean1>(){})
                .adapt(ObservableResponse<UpImgBean1>())
                .subscribeOn(Schedulers.io())
    }
    //上传商品图片
    fun UpFoodImg(image:File):Observable<Response<UpImgBean>>{
        return OkGo.post<UpImgBean>(Constants.UpFoodImg)
                .headers("token",SPUser.getUser(Application()).getToken())
                .params("image",image)
                .converter(object :JsonConvert<UpImgBean>(){})
                .adapt(ObservableResponse<UpImgBean>())
                .subscribeOn(Schedulers.io())
    }
    //删除图片
    fun DelImage(id: Int,slide_id:Int):Observable<Response<MsgBean>>{
        return OkGo.post<MsgBean>(Constants.DelImage)
                .headers("token",SPUser.getUser(Application()).getToken())
                .params("id",id)
                .params("slide_id",slide_id)
                .converter(object :JsonConvert<MsgBean>(){})
                .adapt(ObservableResponse<MsgBean>())
                .subscribeOn(Schedulers.io())
    }
    //修改商品
    fun EditFood(id: Int,goods_name:String,type_id:Int,price:String,details:String?,is_discount:Int,discount:String?,is_restrictions:Int
    ,num:Int,is_sell:Int,photos:String?,attr:String?):Observable<Response<MsgBean>>{
        return OkGo.post<MsgBean>(Constants.EditFood)
                .headers("token",SPUser.getUser(Application()).getToken())
                .params("id",id)
                .params("goods_name",goods_name)
                .params("type_id",type_id)
                .params("price",price)
                .params("details",details)
                .params("is_discount",is_discount)
                .params("discount",discount)
                .params("is_restrictions",is_restrictions)
                .params("num",num)
                .params("is_sell",is_sell)
                .params("photos",photos)
                .params("attr",attr)
                .converter(object :JsonConvert<MsgBean>(){})
                .adapt(ObservableResponse<MsgBean>())
                .subscribeOn(Schedulers.io())
    }
    //添加商品
    fun AddFood(goods_name:String,type_id:Int,price:String,details:String?,is_discount:Int,discount:String?,is_restrictions:Int
                ,num:Int,is_sell:Int,photos:String?,attr:String?):Observable<Response<MsgBean>>{
        return OkGo.post<MsgBean>(Constants.AddFood)
                .headers("token",SPUser.getUser(Application()).getToken())
                .params("goods_name",goods_name)
                .params("type_id",type_id)
                .params("price",price)
                .params("details",details)
                .params("is_discount",is_discount)
                .params("discount",discount)
                .params("is_restrictions",is_restrictions)
                .params("num",num)
                .params("is_sell",is_sell)
                .params("photos",photos)
                .params("attr",attr)
                .converter(object :JsonConvert<MsgBean>(){})
                .adapt(ObservableResponse<MsgBean>())
                .subscribeOn(Schedulers.io())
    }
}
